package com.iotechn.unimall.app.api.drivercar;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.iotechn.unimall.core.exception.ServiceException;
import com.iotechn.unimall.data.domain.DrvierCarDO;
import com.iotechn.unimall.data.mapper.DrvierCarMapper;
import com.iotechn.unimall.data.model.Page;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DriverCarServiceImpl implements DriverCarService {

    @Autowired
    private DrvierCarMapper drvierCarMapper;


    @Override
    public Page<DrvierCarDO> driverCarPage(Integer page, Integer limit) throws ServiceException {

        Wrapper<DrvierCarDO> wrapper = new EntityWrapper<DrvierCarDO>();
        /**if (!StringUtils.isEmpty(name)) {
         wrapper.like("username", name);
         }**/
        wrapper.eq("status", 0);
        wrapper.eq("apply_status", 1);

        wrapper.orderBy("id", false);
        Integer count = drvierCarMapper.selectCount(wrapper);
        List<DrvierCarDO> PlantCarLogDOS = drvierCarMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
        return new Page<>(PlantCarLogDOS, page, limit, count);
    }

    @Override
    public Object reserveDriver(Long userId) throws ServiceException {
        return null;
    }

    @Override
    public DrvierCarDO detailByUserId(Long userId) throws ServiceException {
        return drvierCarMapper.getDriverByUserId(userId);
    }

}
